import { dateFormat } from '@vimi/utils-tool'
import { mapGetters } from 'vuex'

export const fastParams = {
  computed: {
    ...mapGetters(['user', 'userId', 'clientId']),
    status() {
      return this.$route.query.status
    },
    productId() {
      return this.$route.query.id || ''
    },
    baseParams() {
      // const {
      //   queryAddressCode,
      //   clientOrgClassType
      // } = this.user
      return {
        // address_code: queryAddressCode,
        // 'bank_type.eq': clientOrgClassType,
        'bank_id.eq': this.clientId,
        'project_type_id.eq': this.productId,
      }
    },
  },
}

export const baseTableColumns = [
  { attrs: { label: '借款客户', prop: 'customer_name', minWidth: '120px' } },
  { attrs: { label: '客户类型', prop: 'org_class_name', align: 'center' } },
  { attrs: { label: '贷款金额(万元)', prop: 'funds', align: 'center' } },
  { attrs: { label: '放款日期', prop: 'loadDate', align: 'center', minWidth: '100px' } },
  { attrs: { label: '还款日期', prop: 'loadEndDate', align: 'center', minWidth: '100px' } },
  {
    attrs: { label: '所属行业', prop: 'ind_class_name', align: 'center', minWidth: '110px' },
  },
  { attrs: { label: '十二大产业', prop: 'main_business', align: 'center', minWidth: '110px' } },
  { attrs: { label: '贷款用途', prop: 'funds_use_dir', align: 'center' }, slot: 'use' },
  { attrs: { label: '导入银行', prop: 'bank_name', align: 'center' } },
]

export const pickerOptions = {
  disabledDate(time) {
    const date = new Date()
    const month = date.getMonth()
    let maxTime = new Date(date.getFullYear(), month)
    return time < new Date(2020, 1) || time > maxTime
  },
}

export const dataAdapter = item => {
  item.loadDate = dateFormat(item.load_date, 'yyyy-MM-dd')
  item.loadEndDate = dateFormat(item.load_end_date, 'yyyy-MM-dd')
  item.createTime = dateFormat(item.create_time, 'yyyy-MM-dd hh:mm')
  item.funds = +item.reply_funds || +item.approved_funds || +item.apply_funds || ''
  return item
}

export const projectIsCompany = projectData => {
  return !!projectData.register_no
}

// 批次对应 key 值
// 项目提交 customer_related_quick_batch_id
// 项目确认 project_approval_batch_bank_id
// 提前解保 un_gua_advance_batch_id
// 正常解保 un_gua_batch_id
// 代偿解保 un_gua_comps_batch_id

export const parseCascaderDate = (date = []) => {
  const { length } = date
  let [year, month, day] = date
  month = `${month}`.padStart(2, '0')
  day = `${day}`.padStart(2, '0')

  switch (length) {
    case 0:
      return ['', '']
    case 1:
      return [`${year}-01-01`, `${year}-12-31 23:59:59`]
    case 2:
      return [`${year}-${month}-01`, `${year}-${month}-31 23:59:59`]
    case 3:
      return [`${year}-${month}-${day}`, `${year}-${month}-${day} 23:59:59`]
    default:
      return ['', '']
  }
}
